package com.nononsenseapps.feeder.ui.rule

import android.app.Application
import androidx.paging.DataSource
import cn.ekuma.odbo.mobile.room.BaseDao
import cn.ekuma.odbo.mobile.ui.AbstractPagedListEditorViewModel
import com.nononsenseapps.feeder.db.entity.Feed
import com.nononsenseapps.feeder.db.entity.FeedRule
import com.nononsenseapps.feeder.db.room.*

class FeedRuleEditorViewModel(application: Application): AbstractPagedListEditorViewModel<FeedRule,Int>(application) {

     lateinit var  feedRuleDao:FeedRuleDao
     lateinit var  feedDao:FeedDao

    override fun initViewModel() {
        feedRuleDao= AppDatabase.getInstance(getApplication()).feedRuleDao()
        feedDao= AppDatabase.getInstance(getApplication()).feedDao()
    }

    override fun buildDataSourse(): DataSource<Int, FeedRule> {
        return feedRuleDao.listAll().create()
    }

    fun loadSubscribeFeeds():List<Feed> =
          feedDao.loadSubscribeFeeds()

    override fun getBaseDao(): BaseDao<FeedRule> {
        return feedRuleDao
    }
}